package listtest;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-16
 * Time: 10:20
 */
public class Test {
    public static void main(String[] args) {
        //ArrayList是以泛型方式实现的，使用时必须要先实例化
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        System.out.println(arrayList);

        System.out.println();
        System.out.println("=========");

        ArrayList<Integer> arrayList1 = new ArrayList<>(arrayList);
        arrayList1.add(111);
        System.out.println(arrayList1);

        System.out.println();
        System.out.println("=========");

        ArrayList<String> stringArrayList = new ArrayList<>();
        stringArrayList.add("haha");
        stringArrayList.add("this");
        stringArrayList.add("is");
        stringArrayList.add("father");
        System.out.println(stringArrayList);
        //error: ArrayList<Integer> arrayList2 = new ArrayList<>(stringArrayList);

    }
    public static void main1(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.display();

        System.out.println();
        System.out.println("=========");

        myArrayList.add(1, 10);
        myArrayList.display();

        System.out.println();
        System.out.println("=========");

        System.out.println(myArrayList.contains(3));
        System.out.println(myArrayList.indexOf(6));

        System.out.println();
        System.out.println("=========");

        System.out.println(myArrayList.get(0));
        System.out.println(myArrayList.get(1));
        System.out.println(myArrayList.get(2));
        System.out.println(myArrayList.get(3));
        System.out.println(myArrayList.get(4));

        System.out.println();
        System.out.println("=========");

        myArrayList.set(1, 15);
        myArrayList.display();

        System.out.println();
        System.out.println("=========");

        myArrayList.remove(15);
        myArrayList.display();

        System.out.println();
        System.out.println("=========");

        myArrayList.clear();
        myArrayList.display();
    }
}
